<?php
namespace app\common\model;
use think\Request;
use think\Hook;

/**
 * 订单模型
 */
class Order extends BaseModel
{
    protected $name = 'order';

    /**
     * 订单模型初始化
     */
    public static function init()
    {
        parent::init();
        // 监听订单处理事件
        $static = new static;
        Hook::listen('order', $static);
    }

    /**
     * 订单商品列表
     */
    public function goods()
    {
        return $this->hasMany('OrderGoods');
    }

    /**
     * 关联订单收货地址表
     */
    public function address()
    {
        return $this->hasOne('OrderAddress');
    }

    /**
     * 关联用户表
     */
    public function user()
    {
        return $this->belongsTo('User');
    }
	
	/**
     * 关联餐桌/包间表
     */
    public function table()
    {
        return $this->belongsTo('Table');
    }
	
	/**
     * 关联门店表
     */
    public function shop()
    {
        return $this->belongsTo('Shop');
    }

	/**
     * 关联店员
     */
    public function clerk()
    {
        return $this->belongsTo('ShopClerk');
    }
	
	/**
     * 格式化到店时间
     */
    public function getArriveTimeAttr($value)
    {
		if($value){
			return date("Y-m-d H:i:s",$value);
		}
        return $value;
    }
	
	/**
     * 配送方式
     */
    public function getDeliverModeAttr($value)
    {
        $status = ['自配', '顺丰', '达达', 'UU'];
        return ['text' => $status[$value], 'value' => $value];
    }
	
    /**
     * 付款状态
     */
    public function getPayStatusAttr($value)
    {
        $status = [10 => '待 付 款', 20 => '已 付 款'];
        return ['text' => $status[$value], 'value' => $value];
    }

    /**
     * 商家状态
     */
	public function getDeliveryStatusAttr($value)
    {
        $status = [0 => '待 接 单', 10 => '已 接 单', 20 => '烹制完成', 30 => '驳回订单'];
        return ['text' => $status[$value], 'value' => $value];
    }
	

    /**
     * 配送/用餐状态
     */	
	public function getReceiptStatusAttr($value)
    {
        $status = [10 => '等待骑手', 20 => '派 送 中', 30 => '上餐完毕'];
        return ['text' => $status[$value], 'value' => $value];
    }
	

    /**
     * 订单状态
     */
    public function getOrderStatusAttr($value)
    {
        $status = [10 => '进 行 中', 20 => '被 取 消', 30 => '已 完 成'];
        return ['text' => $status[$value], 'value' => $value];
    }
	
	/**
     * 订单列表
     */
    public function getLists($where,$whereOr=[])
    {
        return $this->with(['goods.image', 'address', 'user', 'shop', 'table', 'clerk'])
            ->where($where)
			->whereOr($whereOr)
            ->order(['create_time' => 'desc'])->paginate(10, false, [
                'query' => Request::instance()->request()
            ]);
    }

    /**
     * 订单详情
     */
    public static function detail($order_id)
    {
		return self::useGlobalScope(false)
			->with(['goods' => ['image', 'spec', 'goods'], 'user', 'address', 'shop', 'table','clerk'])
			->where(['order_id' => $order_id])
			->find();
    }
	
	/**
     * 订单详情 - 回调
     */
    public static function getOrder($order_id)
    {
		return self::useGlobalScope(false)->where(['order_id' => $order_id])->find();
    }
	
	/**
     * 订单详情 - 配送回调
     */
    public static function getDetail($deliver_id)
    {
		return self::useGlobalScope(false)->where(['deliver_id' => $deliver_id])->find();
    }
	
	/**
     * 确认发货
     */
    public function delivery($data=[])
    {
		$receipt_status = 10;
        if ($this['pay_status']['value'] == 10
            || $this['delivery_status']['value'] == 20) {
            $this->error = '该订单不合法';
            return false;
        }
		if($this['table_id']==3){
			if($data['shop_clerk_id']==''){
				$this->error = '请选择配送员';
				return false;
			}
		}else{
			$data['shop_clerk_id'] = '';
			$receipt_status = 30;
		}
		//发送订阅消息
		post_tpl('take',$this->order_id);
        return $this->save([
            'shop_clerk_id' => $data['shop_clerk_id'],
            'delivery_status' => 20,
            'delivery_time' => time(),
			'receipt_status' => $receipt_status,
            'receipt_time' => time()
        ]);
    }
	
	/**
     * 根据时间段统计数量
     */
    public static function getDateCount($shop)
    {
		$self = new static;
		 // 筛选条件
        $filter = [];
        $shop['shop_id'] > 0 && $filter['shop_id'] = $shop['shop_id'];
		$wxapp_id = $self::$wxapp_id;
		$wxapp_id > 0 && $filter['wxapp_id'] = $wxapp_id;
		$filter['pay_status'] = ['=',20];
        $count = array();
		$count['count'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->count();
		$count['pay_price'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->sum('pay_price');
		$count['total_price'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->sum('total_price');
		$count['activity_price'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->sum('activity_price');
		$count['express_price'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->sum('express_price');
		$count['pack_price'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->sum('pack_price');
		$count['ware_price'] = self::useGlobalScope(false)->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->sum('ware_price');
		$count['tang'] = self::useGlobalScope(false)->where(['table_id'=>['<>',2],'table_id'=>['<>',3]])->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->count();
		$count['qu'] = self::useGlobalScope(false)->where(['table_id' => 2])->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->count();
		$count['wai'] = self::useGlobalScope(false)->where(['table_id' => 3])->where('create_time','>',$shop['star'])->where('create_time','<',$shop['end'])->where($filter)->count();
		return $count;
    }

	/**
     * 根据条件统计数量
     */
    public static function getCount($shop_id=0)
    {
		$self = new static;
		 // 筛选条件
        $filter = [];
        $shop_id > 0 && $filter['shop_id'] = $shop_id;
		$wxapp_id = $self::$wxapp_id;
		$wxapp_id > 0 && $filter['wxapp_id'] = $wxapp_id;
        $count = array();
		//全部
		$count[0]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->count();
		//$count[0]['tang'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->count();
		//$count[0]['qu'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('table_id',2)->where($filter)->count();
		//$count[0]['wai'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('table_id',3)->where($filter)->count();
		//$count[0]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('pay_price');
		//$count[0]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('total_price');
		//$count[0]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('activity_price');
		//$count[0]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('express_price');
		//$count[0]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('pack_price');
		//$count[0]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('ware_price');
		//今天
		$star = strtotime(date('Y-m-d 00:00:00',time()));
		$count[1]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->count();
		$count[1]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('pay_price');
		$count[1]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('total_price');
		$count[1]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('activity_price');
		$count[1]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('express_price');
		$count[1]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('pack_price');
		$count[1]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('ware_price');
		$count[1]['tang'] = self::useGlobalScope(false)->where(['pay_status'=>20,'table_id'=>['<>',2],'table_id'=>['<>',3]])->where('create_time','>',$star)->where($filter)->count();
		$count[1]['qu'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 2])->where('create_time','>',$star)->where($filter)->count();
		$count[1]['wai'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 3])->where('create_time','>',$star)->where($filter)->count();
		//昨天
		$star = strtotime("-1 day");
		$end = strtotime(date('Y-m-d 00:00:00',time()));
		$count[2]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[2]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		$count[2]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		$count[2]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		$count[2]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		$count[2]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		$count[2]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		$count[2]['tang'] = self::useGlobalScope(false)->where(['pay_status'=>20,'table_id'=>['<>',2],'table_id'=>['<>',3]])->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[2]['qu'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 2])->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[2]['wai'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 3])->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		//前天
		$star = strtotime("-2 day");
		$end = strtotime("-1 day");
		$count[3]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[3]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//$count[3]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		//$count[3]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		//$count[3]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		//$count[3]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		//$count[3]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		//-4天
		$star = strtotime("-3 day");
		$end = strtotime("-2 day");
		$count[4]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[4]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//$count[4]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		//$count[4]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		//$count[4]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		//$count[4]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		//$count[4]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		//-5天
		$star = strtotime("-4 day");
		$end = strtotime("-3 day");
		$count[5]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[5]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//$count[5]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		//$count[5]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		//$count[5]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		//$count[5]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		//$count[5]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		//-6天
		$star = strtotime("-5 day");
		$end = strtotime("-4 day");
		$count[6]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[6]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//$count[6]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		//$count[6]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		//$count[6]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		//$count[6]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		//$count[6]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		//-7天
		$star = strtotime("-6 day");
		$end = strtotime("-5 day");
		$count[7]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[7]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//$count[7]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		//$count[7]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		//$count[7]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		//$count[7]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		//$count[7]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		//本月起至时间 - 月度统计 
		$end = mktime(0,0,0,date('m'),1,date('y')); 
		$count[8]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->count();
		$count[8]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('pay_price');
		$count[8]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('total_price');
		$count[8]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('activity_price');
		$count[8]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('express_price');
		$count[8]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('pack_price');
		$count[8]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('ware_price');
		$count[8]['tang'] = self::useGlobalScope(false)->where(['pay_status'=>20,'table_id'=>['<>',2],'table_id'=>['<>',3]])->where('create_time','>',$end)->where($filter)->count();
		$count[8]['qu'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 2])->where('create_time','>',$end)->where($filter)->count();
		$count[8]['wai'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 3])->where('create_time','>',$end)->where($filter)->count();
		//上月开始  
		$star = mktime(0,0,0,date('m')-1,1,date('y')); 
		$count[9]['count'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[9]['pay_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
        $count[9]['total_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('total_price');
		$count[9]['activity_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('activity_price');
		$count[9]['express_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('express_price');
		$count[9]['pack_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pack_price');
		$count[9]['ware_price'] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('ware_price');
		$count[9]['tang'] = self::useGlobalScope(false)->where(['pay_status'=>20,'table_id'=>['<>',2],'table_id'=>['<>',3]])->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[9]['qu'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 2])->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[9]['wai'] = self::useGlobalScope(false)->where(['pay_status' => 20,'table_id' => 3])->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		return $count;
    }
	
	/**
     * 根据条件统计数量
     */
    public static function getAllCount($shop_id=0)
    {
		$self = new static;
		 // 筛选条件
        $filter = [];
        $shop_id > 0 && $filter['shop_id'] = $shop_id;
		$wxapp_id = $self::$wxapp_id;
		$wxapp_id > 0 && $filter['wxapp_id'] = $wxapp_id;
        $count = array();
		//全部
		$count[0][0] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->count();
		$count[1][0] = self::useGlobalScope(false)->where('pay_status','=',20)->where($filter)->sum('pay_price');
		//今天
		$star = strtotime(date("Y-m-d"),time());
		$count[0][1] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->count();
		$count[1][1] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where($filter)->sum('pay_price');
		//昨天
		$star = strtotime("-1 day");
		$end = strtotime(date("Y-m-d"),time());
		$count[0][2] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][2] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//前天
		$star = strtotime("-2 day");
		$end = strtotime("-1 day");
		$count[0][3] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][3] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//-4天
		$star = strtotime("-3 day");
		$end = strtotime("-2 day");
		$count[0][4] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][4] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//-5天
		$star = strtotime("-4 day");
		$end = strtotime("-3 day");
		$count[0][5] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][5] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//-6天
		$star = strtotime("-5 day");
		$end = strtotime("-4 day");
		$count[0][6] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][6] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		//-7天
		$star = strtotime("-6 day");
		$end = strtotime("-5 day");
		$count[0][7] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][7] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		
		//本月起至时间 - 月度统计 
		$end = mktime(0,0,0,date('m'),1,date('y')); 
		$count[0][8] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->count();
		$count[1][8] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$end)->where($filter)->sum('pay_price');
		
		//上月开始  
		$star = mktime(0,0,0,date('m')-1,1,date('y')); 
		$count[0][9] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][9] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		
		//上上月开始  
		$star = mktime(0,0,0,date('m')-2,1,date('y')); 
		$count[0][10] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();
		$count[1][10] = self::useGlobalScope(false)->where('pay_status','=',20)->where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->sum('pay_price');
		
		
        return $count;
    }

}
